import logging
from fastapi import FastAPI, Request
from src.utils.config import read_config
from src.router import register_router
from src.middleware import register_middleware
from src.core.life import lifespan
from src.middleware.exception import register_exception   
from src.core.log import log

 
 
 
def startApp(): 
    app = FastAPI(lifespan=lifespan)

    # 中间件
    register_middleware(app)

    # 注册路由
    register_router(app)

    # 注册错误捕获
    register_exception(app)

    config = read_config()

    # 开启日志显示
    if config and config.get("log") and config.get("log")["debug"]:
        logging.basicConfig(level=logging.DEBUG)

    return (app,config)